package com.ai.wx.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ai.core.dao.BaseDaoI;
import com.ai.wx.entity.SystemInfo;
import com.ai.wx.service.SystemService;

@Service
public class SystemServiceImpl implements SystemService {

	@Autowired
	private BaseDaoI<SystemInfo> systemInfoDao;

	public String getAccessToken() {

		SystemInfo systemInfo = systemInfoDao.get(SystemInfo.class, 1);

		return systemInfo.getValue();
	}

	public String getJsapiTicket() {

		SystemInfo systemInfo = systemInfoDao.get(SystemInfo.class, 2);

		return systemInfo.getValue();
	}
	

	public String getUserName() {

		SystemInfo systemInfo = systemInfoDao.get(SystemInfo.class, 3);

		return systemInfo.getValue();
	}

	public String getPassWord() {

		SystemInfo systemInfo = systemInfoDao.get(SystemInfo.class, 4);

		return systemInfo.getValue();
	}
	
	public void updateAccessToken(String accessToken){
		SystemInfo obj = systemInfoDao.get(SystemInfo.class, 1);
		obj.setValue(accessToken);
		obj.setTime(new Date());
		systemInfoDao.save(obj);
	}
	

	public void updateJsapiTicket(String jsapiTicket){
		SystemInfo obj = systemInfoDao.get(SystemInfo.class, 2);
		obj.setValue(jsapiTicket);
		obj.setTime(new Date());
		systemInfoDao.save(obj);
	}
}
